package com.hmall.item;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import lombok.Data;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Optional;

@Data
public class TotalStandardDataDto {

    private static final String UPDATE_TITLE = "数据更新时间";

    
    private static final String BASIC_TITLE = "基础数据";

    
    private static final String NATIONAL_TITLE = "国标数据";

    
    private static final String BATTERY_TITLE = "电池详细数据";

    
    private static final String SECRET_TITLE = "机密数据";


    @ExcelProperty(value = {UPDATE_TITLE, "数据更新时间"})
    @DateTimeFormat("yyyy-MM-dd HH:mm:ss.SSS")
    protected Date collectTime;

    @ExcelProperty(value = {BASIC_TITLE, "车架号"})
    protected String vinCode;

    @ExcelProperty(value = {BASIC_TITLE, "云盒码"})
    protected String tboxSn;

    @ExcelProperty(value = {BASIC_TITLE, "iccid"})
    protected String iccid;

    @ExcelProperty(value = {BASIC_TITLE, "电池编码"})
    protected String batterySn;

    @ExcelProperty(value = {BASIC_TITLE, "车辆状态"})
    protected String vehicleStateName;

    @ExcelProperty(value = {BASIC_TITLE, "设备状态"})
    protected String onLineStateName;

    /**
     * 仪表里程，单位km
     */
    @ExcelProperty(value = {BASIC_TITLE, "总里程"})
    protected Float totalMileage;

    @ExcelProperty(value = {NATIONAL_TITLE, "总里程"})
    private Float totalVoltage;

    @ExcelProperty(value = {NATIONAL_TITLE, "总电流"})
    private Float totalCurrent;

    @ExcelProperty(value = {NATIONAL_TITLE, "车速"})
    private Float speed;

    @ExcelProperty(value = {NATIONAL_TITLE, "定位状态"})
    private Integer isInvalid;

    @ExcelProperty(value = {NATIONAL_TITLE, "定位方式"})
    private String isBD;

    @ExcelProperty(value = {NATIONAL_TITLE, "经度"})
    private String lng;

    @ExcelProperty(value = {NATIONAL_TITLE, "纬度"})
    private String lat;

    @ExcelProperty(value = {NATIONAL_TITLE, "温度"})
    private Integer highTempValue;

    //多个单体电池电压
    @ExcelIgnore
    private Float[] batteryVoltageList;

    @ExcelProperty(value = {NATIONAL_TITLE, "单体电池电压"})
    private String batteryVoltageStr;

    @ExcelProperty(value = {NATIONAL_TITLE, "定位异常报警"})
    private String positionAlarm;

    @ExcelProperty(value = {NATIONAL_TITLE, "超速报警"})
    private String overSpeedAlarm;

    @ExcelProperty(value = {NATIONAL_TITLE, "总电压过高"})
    private String highTotalVoltage;

    @ExcelProperty(value = {NATIONAL_TITLE, "充电温度过高"})
    private String highChargingTemp;

    @ExcelProperty(value = {NATIONAL_TITLE, "放电温度过高"})
    private String highDischargeTemp;

    @ExcelProperty(value = {NATIONAL_TITLE, "充电电流过高"})
    private String highChargingCurrent;

    @ExcelProperty(value = {NATIONAL_TITLE, "放电电流过高"})
    private String highDischargeCurrent;

    /**
     * 电池厂商代码
     */
    @ExcelProperty(value = {BATTERY_TITLE, "电池厂商代码"})
    private String factoryCode;

    @ExcelProperty(value = {BATTERY_TITLE, "电池编码1"})
    private String batterySnCode;

    /**
     * 电池型号
     */
    @ExcelProperty(value = {BATTERY_TITLE, "电池型号"})
    private Integer batteryModelType;

    /**
     * 电芯材料
     */
    @ExcelProperty(value = {BATTERY_TITLE, "电芯材料"})
    private String cellMaterial;

    /**
     * 额定电压
     */
    @ExcelProperty(value = {BATTERY_TITLE, "额定电压"})
    private Float ratedVoltage;

    /**
     * 额定容量
     */
    @ExcelProperty(value = {BATTERY_TITLE, "额定容量"})
    private Float ratedCapacity;

    /**
     * 剩余容量SOC（%）
     */
    @ExcelProperty(value = {BATTERY_TITLE, "SOC"})
    private String soc;

    /**
     * bms协议版本号
     */
    @ExcelProperty(value = {BATTERY_TITLE, "BMS协议版本号"})
    private String protoVersion;

    /**
     * bms软件版本号
     */
    @ExcelProperty(value = {BATTERY_TITLE, "BMS软件版本号"})
    private String swVersion;

    /**
     * private
     * BMS当前状态
     */
    @ExcelProperty(value = {BATTERY_TITLE, "BMS当前状态"})
    private String bmsWorkState;

    /**
     * BMS交互状态
     */
    @ExcelIgnore
    private List<String> bmsInteractionStatusList;

    @ExcelProperty(value = {BATTERY_TITLE, "BMS交互状态"})
    private String bmsInteractionStatusListStr;

    /**
     * 电池当前工作电压
     */
    @ExcelProperty(value = {BATTERY_TITLE, "电池当前电压"})
    private String batteryTotalVoltage;

    /**
     * 电池当前工作电流
     */
    @ExcelProperty(value = {BATTERY_TITLE, "电池当前电流"})
    private String batteryTotalCurrent;

    /**
     * MOS温度
     */
    @ExcelProperty(value = {BATTERY_TITLE, "MOS温度"})
    private Integer mosTemp;

    /**
     * 电池最低温度
     */
    @ExcelProperty(value = {BATTERY_TITLE, "电池最低温度"})
    private Integer lowTempValue;

    /**
     * BMS电池工作状态 00b表示放电；01b表示充电，10b表示搁置（默认值），11b故障?
     */
    @ExcelProperty(value = {BATTERY_TITLE, "电池工作状态"})
    private String batteryWorkState;

    /**
     * 循环次数
     */
    @ExcelProperty(value = {BATTERY_TITLE, "电池循环次数"})
    private Long cycleCnt;

    /**
     * 电池最高单体电压
     */
    @ExcelProperty(value = {BATTERY_TITLE, "电池最高单体电压"})
    private Integer singleHighTemp;

    /**
     * 电池最低单体电压
     */
    @ExcelProperty(value = {BATTERY_TITLE, "电池最低单体电压"})
    private Integer singleLowTemp;

    /**
     * 最高单体电压位置
     */
    @ExcelProperty(value = {BATTERY_TITLE, "最高单体电压位置"})
    private Integer singleHighTempPos;

    /**
     * 最低单体电压位置
     */
    @ExcelProperty(value = {BATTERY_TITLE, "最低单体电压位置"})
    private Integer singleLowTempPos;

    /**
     * 最大允许回馈电流
     */
    @ExcelProperty(value = {BATTERY_TITLE, "最大允许回馈电流"})
    private Float maxAllowCurrent;

    /**
     * 请求充电电压
     */
    @ExcelProperty(value = {BATTERY_TITLE, "请求充电电压"})
    private String allowChargeVol;

    /**
     * 请求充电电流
     */
    @ExcelProperty(value = {BATTERY_TITLE, "请求充电电流"})
    private String allowChargeCur;

    /**
     * 充电状态
     */
    @ExcelProperty(value = {BATTERY_TITLE, "充电状态"})
    private String chargeSate;

    /**
     * 电池故障列表
     */
    @ExcelIgnore
    
    private List<String> fault;

    @ExcelProperty(value = {BATTERY_TITLE, "电池故障列表"})
    private String faultStr;

    /**
     * 加密随机数
     */
    @ExcelProperty(value = {SECRET_TITLE, "加密随机数"})
    private Integer encryptRandomNum;

    /**
     * 互认代码
     */
    @ExcelProperty(value = {SECRET_TITLE, "互认代码"})
    private Long mutualRecognitionCode;

    public String getBmsInteractionStatusListStr() {
        return String.join(",", Optional.ofNullable(bmsInteractionStatusList)
                .orElse(Collections.emptyList()));
    }

    public String getFaultStr() {
        return String.join(",", Optional.ofNullable(fault)
                .orElse(Collections.emptyList()));
    }
}
